package com.ktgj.customer.service.impl;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import com.ktgj.common.core.constant.BusinessTypeConstants;
import com.ktgj.common.core.domain.R;
import com.ktgj.common.core.enums.TrainOrderEnum;
import com.ktgj.common.core.utils.DateUtils;
import com.ktgj.common.core.utils.helper.StringHelper;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.log.aspect.LogAspect;
import com.ktgj.customer.domain.*;
import com.ktgj.customer.domain.dto.FinanceOrderRefundmentExamineDTO;
import com.ktgj.customer.domain.vo.CustomerIdVo;
import com.ktgj.customer.domain.vo.FinanceOrderRefundmentVo;
import com.ktgj.customer.mapper.BusinessOrderMapper;
import com.ktgj.customer.mapper.CustomerMapper;
import com.ktgj.customer.service.IBusinessOrderService;
import com.ktgj.customer.service.ICustomerService;
import com.ktgj.customer.service.IEmployeeService;
import com.ktgj.flight.api.RemoteFlightService;
import com.ktgj.flight.api.domain.FlightOrderChangeTickets;
import com.ktgj.flight.api.domain.FlightOrderInfo;
import com.ktgj.flight.api.domain.FlightOrderInfoTickets;
import com.ktgj.hotel.api.RemoteHotelService;
import com.ktgj.hotel.api.domain.HotelOrder;
import com.ktgj.hotel.api.domain.HotelOrderPaydetail;
import com.ktgj.pay.api.RemotePayService;
import com.ktgj.pay.api.domain.YeeBaoResultApi;
import com.ktgj.service.api.RemoteService;
import com.ktgj.sms.api.RemoteSmsService;
import com.ktgj.sms.api.domain.Sms;
import com.ktgj.train.api.RemoteTrainService;
import com.ktgj.train.api.domain.TrainOrder;
import com.ktgj.train.api.domain.TrainOrderRefundrecord;
import org.bouncycastle.math.Primes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.customer.mapper.FinanceOrderRefundmentMapper;
import com.ktgj.customer.service.IFinanceOrderRefundmentService;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.jsf.FacesContextUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * 财务会员退款信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-13
 */
@Service
public class FinanceOrderRefundmentServiceImpl implements IFinanceOrderRefundmentService 
{
    private static final Logger log = LoggerFactory.getLogger(FinanceOrderRefundmentServiceImpl.class);

    @Autowired
    private FinanceOrderRefundmentMapper financeOrderRefundmentMapper;
    @Autowired
    private RemoteFlightService remoteFlightService;
    @Autowired
    private IEmployeeService employeeService;
    @Autowired
    private ICustomerService customerService;
    @Autowired
    private RemoteSmsService remoteSmsService;
    @Autowired
    private RemotePayService remotePayService;
    @Autowired
    private RemoteTrainService remoteTrainService;
    @Autowired
    private RemoteHotelService remoteHotelService;
    @Autowired
    private IBusinessOrderService businessOrderService;
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private BusinessOrderMapper businessOrderMapper;
    @Autowired
    private RemoteService remoteService;

    /**
     * 查询财务会员退款信息
     * 
     * @param refundmentId 财务会员退款信息ID
     * @return 财务会员退款信息
     */
    @Override
    public FinanceOrderRefundment selectFinanceOrderRefundmentById(Long refundmentId)
    {
        return financeOrderRefundmentMapper.selectFinanceOrderRefundmentById(refundmentId);
    }

    /**
     * 查询财务会员退款信息列表
     * 
     * @param financeOrderRefundment 财务会员退款信息
     * @return 财务会员退款信息
     */
    @Override
    public List<FinanceOrderRefundment> selectFinanceOrderRefundmentList(FinanceOrderRefundment financeOrderRefundment)
    {
        return financeOrderRefundmentMapper.selectFinanceOrderRefundmentList(financeOrderRefundment);
    }

    /**
     * 新增财务会员退款信息
     * 
     * @param financeOrderRefundment 财务会员退款信息
     * @return 结果
     */
    @Override
    public int insertFinanceOrderRefundment(FinanceOrderRefundment financeOrderRefundment)
    {
        financeOrderRefundment.setCreateTime(DateUtils.getNowDate());
        return financeOrderRefundmentMapper.insertFinanceOrderRefundment(financeOrderRefundment);
    }

    /**
     * 提交审核的批次号顺序递增
     * */
    @Override
    public int number() {
        int i = financeOrderRefundmentMapper.number();
        return i;
    }

    /**
     * 修改财务会员退款信息
     * 
     * @param financeOrderRefundment 财务会员退款信息
     * @return 结果
     */
    @Override
    public int updateFinanceOrderRefundment(FinanceOrderRefundment financeOrderRefundment)
    {
        return financeOrderRefundmentMapper.updateFinanceOrderRefundment(financeOrderRefundment);
    }

    /**
     * 批量删除财务会员退款信息
     * 
     * @param refundmentIds 需要删除的财务会员退款信息ID
     * @return 结果
     */
    @Override
    public int deleteFinanceOrderRefundmentByIds(Long[] refundmentIds)
    {
        return financeOrderRefundmentMapper.deleteFinanceOrderRefundmentByIds(refundmentIds);
    }

    /**
     * 删除财务会员退款信息信息
     * 
     * @param refundmentId 财务会员退款信息ID
     * @return 结果
     */
    @Override
    public int deleteFinanceOrderRefundmentById(Long refundmentId)
    {
        return financeOrderRefundmentMapper.deleteFinanceOrderRefundmentById(refundmentId);
    }

    //会员退款申请列表
    @Override
    public List<FinanceOrderRefundmentList> financeOrderRefundmentList(FinanceOrderRefundmentVo financeOrderRefundmentVo) {
//        if (financeOrderRefundmentVo.getCustomerInformation() != null && !financeOrderRefundmentVo.getCustomerInformation().equals("")){
//            Customer customer = customerMapper.customerByCustomerName(financeOrderRefundmentVo.getCustomerInformation());
//            financeOrderRefundmentVo.setCustomerId(customer.getCustomerId());
//        }

        List<FinanceOrderRefundmentList> financeOrderRefundmentLists = financeOrderRefundmentMapper.financeOrderRefundmentList(financeOrderRefundmentVo);
        if (financeOrderRefundmentLists != null && financeOrderRefundmentLists.size() > 0) {
            financeOrderRefundmentLists.forEach(item -> {
                if (item.getOrderTypeId() != null)
                {
                    if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.customer.getValue())))
                    {
                        item.setOrderTypeId("会员订单");
                    } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.flight.getValue())))
                    {
                        item.setOrderTypeId("机票订单");
                    } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.hotel.getValue())))
                    {
                        item.setOrderTypeId("酒店订单");
                    } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.service.getValue())))
                    {
                        item.setOrderTypeId("贵宾厅、VIP通道订单");
                    } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.train.getValue())))
                    {
                        item.setOrderTypeId("火车票订单");
                    } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.travel.getValue())))
                    {
                        item.setOrderTypeId("旅游订单");
                    }else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.mall.getValue())))
                    {
                        item.setOrderTypeId("商城订单");
                    }
                }


                if (item.getRefundmentType() != null){
                    if (item.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.companyRemittance.getValue()))) {
                        item.setRefundmentType("公司汇款给会员");
                    } else if (item.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.originalRoad.getValue()))) {
                        item.setRefundmentType("原路退回");
                    } else if (item.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.weChat.getValue()))) {
                        item.setRefundmentType("微信自动退款");
                    } else if (item.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.alipay.getValue()))) {
                        item.setRefundmentType("支付宝自动退款");
                    }
                }

                if (item.getStatus() != null){
                    if (item.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.initial.toString()))) {
                        item.setStatus("初始");
                    } else if (item.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.requested.toString()))) {
                        item.setStatus("已申请");
                    } else if (item.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.complete.toString()))) {
                        item.setStatus("完成");
                    } else if (item.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.cancel.toString()))) {
                        item.setStatus("取消");
                    } else if (item.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.reviewed.toString()))) {
                        item.setStatus("已审核");
                    } else if (item.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.deposit.toString()))) {
                        item.setStatus("入预留款");
                    } else if (item.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.auditFailed.toString()))) {
                        item.setStatus("审核失败");
                    } else if (item.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()))) {
                        item.setStatus("退款失败");
                    } else if (item.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refunding.toString()))) {
                        item.setStatus("退款中");
                    }
                }
            });
        }
        if (financeOrderRefundmentVo.getCustomerInformation() != null && !StringHelper.isNullOrEmpty(financeOrderRefundmentVo.getCustomerInformation()))
        {
            financeOrderRefundmentLists = financeOrderRefundmentLists.stream().filter(item->item.getCustomerName().equals(financeOrderRefundmentVo.getCustomerInformation())).collect(Collectors.toList());
        }
        return financeOrderRefundmentLists;
    }

    //退款申请确认
    @Override
    public FinanceOrderRefundmentDetails orderRefundmentDetails(Long refundmentId) {
        FinanceOrderRefundmentDetails refundmentDetails = financeOrderRefundmentMapper.orderRefundmentDetails(refundmentId);
        if (refundmentDetails != null) {
            CustomerIdVo idVo = new CustomerIdVo();
            idVo.setCustomerId(refundmentDetails.getCustomerId());
            try {
                CustomerIdVo customerVo = customerService.customerId(idVo);
                refundmentDetails.setCardNumber(customerVo.getCustomerCard());
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (refundmentDetails.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.companyRemittance.getValue()))) {
                refundmentDetails.setRefundmentType("公司汇款给会员");
            } else if (refundmentDetails.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.originalRoad.getValue()))) {
                refundmentDetails.setRefundmentType("原路退回");
            } else if (refundmentDetails.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.weChat.getValue()))) {
                refundmentDetails.setRefundmentType("微信自动退款");
            } else if (refundmentDetails.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.alipay.getValue()))) {
                refundmentDetails.setRefundmentType("支付宝自动退款");
            } else if (refundmentDetails.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.depositBusiness.getValue()))) {
                refundmentDetails.setRefundmentType("退预留款");
            } else if (refundmentDetails.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.bankCard.getValue()))) {
                refundmentDetails.setRefundmentType("退银行卡");
            }
            if (refundmentDetails.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.initial.toString()))) {
                refundmentDetails.setStatus("初始");
            } else if (refundmentDetails.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.requested.toString()))) {
                refundmentDetails.setStatus("已申请");
            } else if (refundmentDetails.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.complete.toString()))) {
                refundmentDetails.setStatus("完成");
            } else if (refundmentDetails.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.cancel.toString()))) {
                refundmentDetails.setStatus("取消");
            } else if (refundmentDetails.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.reviewed.toString()))) {
                refundmentDetails.setStatus("已审核");
            } else if (refundmentDetails.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.deposit.toString()))) {
                refundmentDetails.setStatus("入预留款");
            } else if (refundmentDetails.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.auditFailed.toString()))) {
                refundmentDetails.setStatus("审核失败");
            } else if (refundmentDetails.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()))) {
                refundmentDetails.setStatus("退款失败");
            } else if (refundmentDetails.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refunding.toString()))) {
                refundmentDetails.setStatus("退款中");
            }

            if (refundmentDetails.getOrderTypeId().equals("1")) {
                BusinessOrder businessOrder = businessOrderService.selectBusinessOrderById(Long.valueOf(refundmentDetails.getOrderId()));
                refundmentDetails.setCollectionAmount(businessOrder.getUsedMoney());
                refundmentDetails.setCollectionType(businessOrder.getPayType());
            } else if (refundmentDetails.getOrderTypeId().equals("2")) {
                Map<String, Long> map = new HashMap<>();
                map.put("orderId", Long.valueOf(refundmentDetails.getOrderId()));
                R<FlightOrderInfo> orderInfo = remoteFlightService.getInfo(map);
                if (orderInfo.getCode() == 200 && orderInfo.getData() != null) {
                    refundmentDetails.setCollectionDate(orderInfo.getData().getPayTime());
                    refundmentDetails.setCollectionAmount(orderInfo.getData().getPayAmount());
                    refundmentDetails.setCollectionType(orderInfo.getData().getPayType());
                }
            } else if (refundmentDetails.getOrderTypeId().equals("3")) {
                R<HotelOrder> hotelOrderR = remoteHotelService.getInfo(Long.valueOf(refundmentDetails.getOrderId()));
                R<HotelOrderPaydetail> orderPaydetailR = remoteHotelService.selectHotelOrderPaydetailByorderId(Long.valueOf(refundmentDetails.getOrderId()));
                if (hotelOrderR.getCode() == 200 && orderPaydetailR.getCode() == 200 && hotelOrderR.getData() != null && orderPaydetailR.getData() != null) {
                    refundmentDetails.setCollectionAmount(hotelOrderR.getData().getPayAmount());
                    refundmentDetails.setCollectionType(orderPaydetailR.getData().getPaytype());
                }
            } else if (refundmentDetails.getOrderTypeId().equals("4")) {
            } else if (refundmentDetails.getOrderTypeId().equals("5")) {
                Map<String, Long> map = new HashMap<>();
                map.put("orderid", Long.valueOf(refundmentDetails.getOrderId()));
                R<TrainOrder> trainOrderR = remoteTrainService.getInfo(map);
                if (trainOrderR.getCode() == 200 && trainOrderR.getData() != null) {
                    //TODO 火车票暂无支付时间 refundmentDetails.setCollectionDate(trainOrderR.getData().getPayTime());
                    refundmentDetails.setCollectionAmount(trainOrderR.getData().getPayamount());
                    refundmentDetails.setCollectionType(trainOrderR.getData().getPayType());
                }
            }
        }
        return refundmentDetails;
    }

    //确认或取消退款申请
    @Override
    public int updateOrderRefundment(Employee employee, FinanceOrderRefundmentDetails refundmentDetails) {
        FinanceOrderRefundment refundment = new FinanceOrderRefundment();
        BeanUtils.copyProperties(refundmentDetails, refundment);
        if (refundmentDetails.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.customer.getValue()))) {
            BusinessOrder businessOrder = new BusinessOrder();
            businessOrder.setOrderId(Long.valueOf(refundmentDetails.getOrderId()));
            businessOrder.setUsedMoney(refundmentDetails.getCollectionAmount());
            businessOrder.setPayType(refundmentDetails.getCollectionType());
            businessOrderService.updateBusinessOrder(businessOrder);
        } else if (refundmentDetails.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.flight.getValue()))) {
            FlightOrderInfo orderInfo = new FlightOrderInfo();
            orderInfo.setOrderId(Long.valueOf(refundmentDetails.getOrderId()));
            orderInfo.setPayAmount(refundmentDetails.getCollectionAmount());
            orderInfo.setPayTime(refundmentDetails.getCollectionDate());
            orderInfo.setPayType(refundmentDetails.getCollectionType());
            remoteFlightService.edit(orderInfo);
        } else if (refundmentDetails.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.hotel.getValue()))) {
            HotelOrder order = new HotelOrder();
            HotelOrderPaydetail orderPaydetail = new HotelOrderPaydetail();
            order.setOrderid(Long.valueOf(refundmentDetails.getOrderId()));
            order.setPayAmount(refundmentDetails.getCollectionAmount());
            orderPaydetail.setPaytype(refundmentDetails.getCollectionType());
            remoteHotelService.edit(order);
            remoteHotelService.updateOrderPaydetailByOrderId(orderPaydetail);
        } else if (refundmentDetails.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.service.getValue()))) {

        } else if (refundmentDetails.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.train.getValue()))) {
            TrainOrder order = new TrainOrder();
            order.setOrderid(Long.valueOf(refundmentDetails.getOrderId()));
            order.setPayamount(refundmentDetails.getCollectionAmount());
            order.setPayType(refundmentDetails.getCollectionType());
            //TODO 火车票暂无支付时间 order.setPayTime(refundmentDetails.getCollectionDate());
            remoteTrainService.edit(order);
        }
        if (refundmentDetails.getStatus().equals(com.ktgj.common.core.constant.FinanceOrderRefundment.requested.toString())) {
            refundment.setEmployeeIdApply(employee.getEmployeeId());
            refundment.setApplyTime(new Date());
        } else if (refundmentDetails.getStatus().equals(com.ktgj.common.core.constant.FinanceOrderRefundment.cancel.toString())) {
            refundment.setEmployeeIdCancel(employee.getEmployeeId());
            refundment.setCancelTime(new Date());
        }
        refundment.setEmployeeIdOperartion(employee.getEmployeeId());
        refundment.setOperationTime(new Date());
        return financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
    }

    //会员退款审核列表
    @Override
    public List<FinanceOrderRefundmentExamine> orderRefundmentExamine(FinanceOrderRefundmentExamineDTO examineDTO) {
        if (examineDTO.getApplyTimeEnd() != null && !"".equals(examineDTO.getApplyTimeEnd()))
            examineDTO.setApplyTimeEnd(examineDTO.getApplyTimeEnd() + " 23:59:59");
        List<FinanceOrderRefundmentExamine> refundmentExamine = financeOrderRefundmentMapper.orderRefundmentExamine(examineDTO);
        if (refundmentExamine != null && refundmentExamine.size() > 0) {
            refundmentExamine.forEach(item -> {
                if (item.getEmployeeIdApply()!=null)
                {
                    Employee employee = employeeService.selectEmployeeById(Long.valueOf(item.getEmployeeIdApply()));
                    item.setEmployeeIdApply(employee.getEmployeeName());
                }
                if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.customer.getValue()))) {
                    item.setOrderTypeId("会员订单");
                    BusinessOrder businessOrder = businessOrderService.selectBusinessOrderById(Long.valueOf(item.getOrderId()));
                    item.setCollectionAmount(businessOrder.getUsedMoney());
                    item.setCollectionType(businessOrder.getPayType());
                } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.flight.getValue()))) {
                    item.setOrderTypeId("机票订单");
                    Map<String, Long> map = new HashMap<>();
                    map.put("orderId", Long.valueOf(item.getOrderId()));
                    R<FlightOrderInfo> orderInfo = remoteFlightService.getInfo(map);
                    if (orderInfo.getCode() == 200 && orderInfo.getData() != null) {
                        item.setCollectionDate(orderInfo.getData().getPayTime());
                        item.setCollectionAmount(orderInfo.getData().getPayAmount());
                        item.setCollectionType(orderInfo.getData().getPayType());
                    }
                } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.hotel.getValue()))) {
                    item.setOrderTypeId("酒店订单");
                    R<HotelOrder> hotelOrderR = remoteHotelService.getInfo(Long.valueOf(item.getOrderId()));
                    R<HotelOrderPaydetail> orderPaydetailR = remoteHotelService.selectHotelOrderPaydetailByorderId(Long.valueOf(item.getOrderId()));
                    if (hotelOrderR.getCode() == 200 && orderPaydetailR.getCode() == 200 && hotelOrderR.getData() != null && orderPaydetailR.getData() != null) {
                        item.setCollectionAmount(hotelOrderR.getData().getPayAmount());
                        item.setCollectionType(orderPaydetailR.getData().getPaytype());
                    }
                } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.service.getValue()))) {
                    item.setOrderTypeId("贵宾厅、VIP通道订单");
                } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.train.getValue()))) {
                    item.setOrderTypeId("火车票订单");
                    Map<String, Long> map = new HashMap<>();
                    map.put("orderid", Long.valueOf(item.getOrderId()));
                    R<TrainOrder> trainOrderR = remoteTrainService.getInfo(map);
                    if (trainOrderR.getCode() == 200 && trainOrderR.getData() != null) {
                        //TODO 火车票暂无支付时间 item.setCollectionDate(trainOrderR.getData().getPayTime());
                        item.setCollectionAmount(trainOrderR.getData().getPayamount());
                        item.setCollectionType(trainOrderR.getData().getPayType());
                    }
                }else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.travel.getValue())))
                {
                    item.setOrderTypeId("旅游订单");
                }else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.mall.getValue())))
                {
                    item.setOrderTypeId("商城订单");
                }
                Customer customer = customerService.selectCustomerById(Long.valueOf(item.getCustomerName()));
                item.setCustomerName(customer.getCustomerName());
                CustomerIdVo customerIdVo = new CustomerIdVo();
                customerIdVo.setCustomerId(customer.getCustomerId());
                try {
                    CustomerIdVo idVo = customerService.customerId(customerIdVo);
                    item.setCardCode(idVo.getCustomerCard());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
        return refundmentExamine;
    }

    //修改退款审核
    @Override
    public int updateRefundmentExamine(Employee employee, boolean isSuccess, List<Object> refundmentId) {
        if (isSuccess) {
            Long max = financeOrderRefundmentMapper.batchNumberMax();
            for (Object aLong : refundmentId) {
                FinanceOrderRefundment financeOrderRefundment = new FinanceOrderRefundment();
                financeOrderRefundment.setRefundmentId(Long.valueOf(aLong.toString()));
                financeOrderRefundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.reviewed.toString()));
                financeOrderRefundment.setBatchNumber(max + 1L);
                financeOrderRefundment.setReviewed(employee.getEmployeeId());
                financeOrderRefundment.setReviewedTime(new Date());
                int refundment = updateFinanceOrderRefundment(financeOrderRefundment);
                if (refundment == 0) {
                    return refundment;
                }
            }
            return 1;
        } else {
            FinanceOrderRefundment financeOrderRefundment = new FinanceOrderRefundment();
            financeOrderRefundment.setRefundmentId(Long.valueOf(refundmentId.get(0).toString()));
            financeOrderRefundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.auditFailed.toString()));
            return updateFinanceOrderRefundment(financeOrderRefundment);
        }
    }

    //出纳员完成退款列表
    @Override
    public List<CompletesRefundList> completesRefundList(String reviewedTime, String reviewedTimeEnd, String employeeIdApply, String plfkformName) {
        List<CompletesRefundList> refundLists = new ArrayList<>();
        if (reviewedTimeEnd != null && !"".equals(reviewedTimeEnd))
            reviewedTimeEnd = reviewedTimeEnd + " 23:59:59";
        List<FinanceOrderRefundment> refundments = financeOrderRefundmentMapper.orderRefundmentList(reviewedTime, reviewedTimeEnd, employeeIdApply, plfkformName);
        Map<Long, List<FinanceOrderRefundment>> collect = refundments.stream().collect(Collectors.groupingBy(FinanceOrderRefundment::getBatchNumber));
        for (Map.Entry<Long, List<FinanceOrderRefundment>> longListEntry : collect.entrySet()) {
            CompletesRefundList completesRefundList = new CompletesRefundList();
            Long key = longListEntry.getKey();
            completesRefundList.setBatchNumber(key);
            List<FinanceOrderRefundment> value = longListEntry.getValue();
            Employee employee = employeeService.selectEmployeeById(value.get(0).getReviewed());
            if (employee!=null)
            {
                completesRefundList.setReviewed(employee.getEmployeeName());
            }
            completesRefundList.setReviewedTime(value.get(0).getReviewedTime());
            completesRefundList.setApplyNumber((long) value.size());
            completesRefundList.setStatus(value.get(0).getStatus());
            completesRefundList.setPlfkformName(value.get(0).getPlfkformName());
            BigDecimal applyPrice = new BigDecimal(0);
            for (FinanceOrderRefundment refundment : value) {
                applyPrice = applyPrice.add(refundment.getRefundmentAmount());
            }
            completesRefundList.setApplyPrice(applyPrice);
            refundLists.add(completesRefundList);
        }
        return refundLists;
    }

    //批量付款列表
    @Override
    public List<FinanceOrderRefundmentExamine> bulkPayment(String reviewedTime, String reviewedTimeEnd, String orderId, Long batchNumber) {
        if (reviewedTimeEnd != null && !reviewedTimeEnd.equals(""))
            reviewedTimeEnd = reviewedTimeEnd + " 23:59:59";
        List<FinanceOrderRefundmentExamine> refundmentExamines = financeOrderRefundmentMapper.bulkPayment(reviewedTime, reviewedTimeEnd, orderId, batchNumber);
        if (refundmentExamines != null && refundmentExamines.size() > 0) {
            refundmentExamines.forEach(item -> {
                Employee employee = employeeService.selectEmployeeById(Long.valueOf(item.getEmployeeIdApply()));
                item.setEmployeeIdApply(employee.getEmployeeName());
                if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.customer.getValue()))) {
                    item.setOrderTypeId("会员订单");
                } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.flight.getValue()))) {
                    item.setOrderTypeId("机票订单");
                } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.hotel.getValue()))) {
                    item.setOrderTypeId("酒店订单");
                } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.service.getValue()))) {
                    item.setOrderTypeId("贵宾厅、VIP通道订单");
                } else if (item.getOrderTypeId().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.train.getValue()))) {
                    item.setOrderTypeId("火车票订单");
                }
                Customer customer = customerService.selectCustomerById(Long.valueOf(item.getCustomerName()));
                item.setCustomerName(customer.getCustomerName());
                if (item.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.companyRemittance.getValue()))) {
                    item.setRefundmentType("公司汇款给会员");
                } else if (item.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.originalRoad.getValue()))) {
                    item.setRefundmentType("原路退回");
                } else if (item.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.weChat.getValue()))) {
                    item.setRefundmentType("微信自动退款");
                } else if (item.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.alipay.getValue()))) {
                    item.setRefundmentType("支付宝自动退款");
                }
            });
        }
        return refundmentExamines;
    }

    //退款确认
    @Override
    public FinanceOrderRefundmentExamine refundConfirm(Long refundmentId) {
        FinanceOrderRefundmentExamine refundConfirm = financeOrderRefundmentMapper.refundConfirm(refundmentId);
        refundConfirm.setRefundBank(refundConfirm.getBankname());
        Customer customer = customerService.selectCustomerById(Long.valueOf(refundConfirm.getCustomerName()));
        refundConfirm.setCustomerName(customer.getCustomerName());
        BASE64Encoder encoder = new BASE64Encoder();
        try {
            String encode = encoder.encode(customer.getContractPhoneOne().getBytes("UTF-8"));
            refundConfirm.setCustomerPhone(encode);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        if (refundConfirm.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.companyRemittance.getValue()))) {
            refundConfirm.setRefundmentType("公司汇款给会员");
        } else if (refundConfirm.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.originalRoad.getValue()))) {
            refundConfirm.setRefundmentType("原路退回");
        } else if (refundConfirm.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.weChat.getValue()))) {
            refundConfirm.setRefundmentType("微信自动退款");
        } else if (refundConfirm.getRefundmentType().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.alipay.getValue()))) {
            refundConfirm.setRefundmentType("支付宝自动退款");
        }
        if (refundConfirm.getOrderTypeId().equals("1")) {
            BusinessOrder businessOrder = businessOrderService.selectBusinessOrderById(Long.valueOf(refundConfirm.getOrderId()));
            refundConfirm.setCollectionAmount(businessOrder.getUsedMoney());
            refundConfirm.setCollectionType(businessOrder.getPayType());
        } else if (refundConfirm.getOrderTypeId().equals("2")) {
            Map<String, Long> map = new HashMap<>();
            map.put("orderId", Long.valueOf(refundConfirm.getOrderId()));
            R<FlightOrderInfo> orderInfo = remoteFlightService.getInfo(map);
            if (orderInfo.getCode() == 200 && orderInfo.getData() != null) {
                refundConfirm.setCollectionDate(orderInfo.getData().getPayTime());
                refundConfirm.setCollectionAmount(orderInfo.getData().getPayAmount());
                refundConfirm.setCollectionType(orderInfo.getData().getPayType());
            }
        } else if (refundConfirm.getOrderTypeId().equals("3")) {
            R<HotelOrder> hotelOrderR = remoteHotelService.getInfo(Long.valueOf(refundConfirm.getOrderId()));
            R<HotelOrderPaydetail> orderPaydetailR = remoteHotelService.selectHotelOrderPaydetailByorderId(Long.valueOf(refundConfirm.getOrderId()));
            if (hotelOrderR.getCode() == 200 && orderPaydetailR.getCode() == 200 && hotelOrderR.getData() != null && hotelOrderR.getData() != null) {
                refundConfirm.setCollectionAmount(hotelOrderR.getData().getPayAmount());
                refundConfirm.setCollectionType(orderPaydetailR.getData().getPaytype());
            }
        } else if (refundConfirm.getOrderTypeId().equals("4")) {
        } else if (refundConfirm.getOrderTypeId().equals("5")) {
            Map<String, Long> map = new HashMap<>();
            map.put("orderid", Long.valueOf(refundConfirm.getOrderId()));
            R<TrainOrder> trainOrderR = remoteTrainService.getInfo(map);
            if (trainOrderR.getCode() == 200 && trainOrderR.getData() != null) {
                //TODO 火车票暂无支付时间 refundConfirm.setCollectionDate(trainOrderR.getData().getPayTime());
                refundConfirm.setCollectionAmount(trainOrderR.getData().getPayamount());
                refundConfirm.setCollectionType(trainOrderR.getData().getPayType());
            }
        }
        if (refundConfirm.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.initial.toString()))) {
            refundConfirm.setStatus("初始");
        } else if (refundConfirm.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.requested.toString()))) {
            refundConfirm.setStatus("已申请");
        } else if (refundConfirm.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.complete.toString()))) {
            refundConfirm.setStatus("完成");
        } else if (refundConfirm.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.cancel.toString()))) {
            refundConfirm.setStatus("取消");
        } else if (refundConfirm.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.reviewed.toString()))) {
            refundConfirm.setStatus("已审核");
        } else if (refundConfirm.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.deposit.toString()))) {
            refundConfirm.setStatus("入预留款");
        } else if (refundConfirm.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.auditFailed.toString()))) {
            refundConfirm.setStatus("审核失败");
        } else if (refundConfirm.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()))) {
            refundConfirm.setStatus("退款失败");
        } else if (refundConfirm.getStatus().equals(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refunding.toString()))) {
            refundConfirm.setStatus("退款中");
        }
        return refundConfirm;
    }

    //确认或暂不退款
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int isRefundConfirm(Employee employee, FinanceOrderRefundmentExamine refundmentExamine) {
        if (refundmentExamine.getRefundmentIds().get(0) != 0) {
            try
            {
                for (Long refundmentId : refundmentExamine.getRefundmentIds()) {
                    FinanceOrderRefundment refundment = new FinanceOrderRefundment();
                    refundment.setRefundmentId(refundmentId);
                    refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refunding.toString()));
                    refundment.setEmployeeIdReturn(employee.getEmployeeId());
                    int orderRefundment = financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                    if (orderRefundment == 0)
                        return orderRefundment;
                    FinanceOrderRefundment financeOrderRefundment = financeOrderRefundmentMapper.selectFinanceOrderRefundmentById(refundmentId);
                    if (financeOrderRefundment.getRefundmentType() == com.ktgj.common.core.constant.FinanceOrderRefundment.originalRoad.getValue()) {
                        if (financeOrderRefundment.getOrderTypeId() == com.ktgj.common.core.constant.FinanceOrderRefundment.customer.getValue()) {
                            BusinessOrder businessOrder = businessOrderService.selectBusinessOrderById(Long.valueOf(financeOrderRefundment.getOrderId()));
                            //易宝信用卡退款
                            if (businessOrder.getPayType().equals(BusinessTypeConstants.BankCredit.getValue())){
                                Map<String, String> refundMap = new HashMap<>();
                                refundMap.put("jsjOrderId", String.valueOf(businessOrder.getOrdernum()));
                                refundMap.put("bankTrxId", businessOrder.getPartyPayNum());
                                refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                if (businessOrder.getSourceway() == 2) {
                                    refundMap.put("payType", "Crm");
                                } else if (businessOrder.getSourceway() == 6) {
                                    refundMap.put("payType", "App");
                                }
                                yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                            }
                            //易宝借记卡退款
                            else if (businessOrder.getPayType().equals(BusinessTypeConstants.BankDebit.getValue())){
                                Map<String, String> refundMap = new HashMap<>();
                                refundMap.put("jsjOrderId", String.valueOf(businessOrder.getOrdernum()));
                                refundMap.put("bankTrxId", businessOrder.getPartyPayNum());
                                refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                if (businessOrder.getSourceway() == 2) {
                                    refundMap.put("payType", "Crm");
                                } else if (businessOrder.getSourceway() == 6) {
                                    refundMap.put("payType", "App");
                                }
                                yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                            }else if (businessOrder.getPayType().equals(BusinessTypeConstants.Wechat.getValue()))
                            {
                                remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                            }
                            //-
                            //银联二维码退款 TODO 后期完善
                    /*else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                        Map<String, String> refundMap = new HashMap<>();
                        refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                        refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                        refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                        UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                        if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                            //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                            refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                            financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                            return 0;
                        }
                    }*/
                        } else if (financeOrderRefundment.getOrderTypeId() == com.ktgj.common.core.constant.FinanceOrderRefundment.flight.getValue()) {
                            Map<String, Long> map = new HashMap<>();
                            map.put("orderId", Long.valueOf(financeOrderRefundment.getOrderId()));
                            R<FlightOrderInfo> orderInfo = remoteFlightService.getInfo(map);
                            if (orderInfo.getCode() == 200 && orderInfo.getData() != null) {
                                FlightOrderInfoTickets orderInfoTickets = new FlightOrderInfoTickets();
                                orderInfoTickets.setOrderId(Long.valueOf(financeOrderRefundment.getOrderId()));
                                List<FlightOrderInfoTickets> infoTickets = remoteFlightService.orderInfoTicketsList(orderInfoTickets);
                                for (FlightOrderInfoTickets infoTicket : infoTickets) {
                                    if (infoTicket.getChangeDateOrderId() != null) {
                                        FlightOrderChangeTickets orderChangeTickets = new FlightOrderChangeTickets();
                                        orderChangeTickets.setOldTicketNo(infoTicket.getTicketNo());
                                        List<FlightOrderChangeTickets> ticketsList = remoteFlightService.orderChangeTicketsList(orderChangeTickets);
                                        for (FlightOrderChangeTickets flightOrderChangeTickets : ticketsList) {
                                            String[] split = flightOrderChangeTickets.getChangeOrderId().split("-");
                                            if (split[1].equals("G")) {
                                                if (flightOrderChangeTickets.getChangeFee().compareTo(new BigDecimal(0)) == 0) {
                                                    break;
                                                } else {
                                                    //易宝信用卡退款
                                                    if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.BankCredit.getValue())){
                                                        Map<String, String> refundMap = new HashMap<>();
                                                        refundMap.put("jsjOrderId", String.valueOf(flightOrderChangeTickets.getChangeTicketId()));
                                                        refundMap.put("bankTrxId", flightOrderChangeTickets.getBillNo());
                                                        refundMap.put("moneyAmout", flightOrderChangeTickets.getChangeFee().stripTrailingZeros().toPlainString());
                                                        refundMap.put("payType", flightOrderChangeTickets.getSourceTypeId());
                                                        yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                                                    }
                                                    //易宝借记卡退款
                                                    else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.BankDebit.getValue())){
                                                        Map<String, String> refundMap = new HashMap<>();
                                                        refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                                        refundMap.put("bankTrxId", flightOrderChangeTickets.getBillNo());
                                                        refundMap.put("moneyAmout", flightOrderChangeTickets.getChangeFee().stripTrailingZeros().toPlainString());
                                                        refundMap.put("payType", flightOrderChangeTickets.getSourceTypeId());
                                                        yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                                                    }else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.Wechat.getValue()))
                                                    {
                                                        remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                                                    }
                                                    //-
                                                    //银联二维码退款 TODO 后期完善
                                            /*else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                                                Map<String, String> refundMap = new HashMap<>();
                                                refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                                refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                                                refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                                                UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                                                if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                                                    //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                                                    refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                                                    financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                                                    return 0;
                                                }
                                            }*/
                                                }
                                            }
                                        }
                                        break;
                                    }
                                }
                                FlightOrderInfo flightOrderInfo = orderInfo.getData();
                                //易宝信用卡退款
                                if (flightOrderInfo.getPayType().equals(BusinessTypeConstants.BankCredit.getValue())){
                                    Map<String, String> refundMap = new HashMap<>();
                                    refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                    refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                                    refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                    refundMap.put("payType", flightOrderInfo.getSourceTypeId());
                                    yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                                }
                                //易宝借记卡退款
                                else if (flightOrderInfo.getPayType().equals(BusinessTypeConstants.BankDebit.getValue())){
                                    Map<String, String> refundMap = new HashMap<>();
                                    refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                    refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                                    refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                    refundMap.put("payType", flightOrderInfo.getSourceTypeId());
                                    yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                                }else if (flightOrderInfo.getPayType().equals(BusinessTypeConstants.Wechat.getValue()))
                                {
                                    remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                                }
                                //-
                                //银联二维码退款 TODO 后期完善
                        /*else if (flightOrderInfo.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                            Map<String, String> refundMap = new HashMap<>();
                            refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                            refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                            refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                            UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                            if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                                //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                                refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                                financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                                return 0;
                            }
                        }*/
                            }
                        } else if (financeOrderRefundment.getOrderTypeId() == com.ktgj.common.core.constant.FinanceOrderRefundment.hotel.getValue()) {
                            R<HotelOrderPaydetail> orderPaydetailR = remoteHotelService.selectHotelOrderPaydetailByorderId(Long.valueOf(financeOrderRefundment.getOrderId()));
                            R<HotelOrder> info = remoteHotelService.getInfo(Long.valueOf(financeOrderRefundment.getOrderId()));
                            if (orderPaydetailR.getCode() == 200 && info.getCode() == 200 && orderPaydetailR.getData() != null && info.getData() != null) {
                                HotelOrderPaydetail data = orderPaydetailR.getData();
                                HotelOrder infoData = info.getData();
                                //易宝信用卡退款
                                if (data.getPaytype().equals(BusinessTypeConstants.BankCredit.getValue())){
                                    Map<String, String> refundMap = new HashMap<>();
                                    refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                    refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                                    refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                    refundMap.put("payType", infoData.getSourceWay());
                                    yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                                }
                                //易宝借记卡退款
                                else if (data.getPaytype().equals(BusinessTypeConstants.BankDebit.getValue())){
                                    Map<String, String> refundMap = new HashMap<>();
                                    refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                    refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                                    refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                    refundMap.put("payType", infoData.getSourceWay());
                                    yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                                }else if (data.getPaytype().equals(BusinessTypeConstants.Wechat.getValue()))
                                {
                                    remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                                }
                                //-
                                //银联二维码退款 TODO 后期完善
                        /*else if (flightOrderInfo.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                            Map<String, String> refundMap = new HashMap<>();
                            refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                            refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                            refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                            UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                            if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                                //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                                refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                                financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                                return 0;
                            }
                        }*/
                            }
                        } else if (financeOrderRefundment.getOrderTypeId() == com.ktgj.common.core.constant.FinanceOrderRefundment.service.getValue()) {

                        } else if (financeOrderRefundment.getOrderTypeId() == com.ktgj.common.core.constant.FinanceOrderRefundment.train.getValue()) {
                            Map<String, Long> map = new HashMap<>();
                            map.put("orderid", Long.valueOf(financeOrderRefundment.getOrderId()));
                            R<TrainOrder> trainOrderR = remoteTrainService.getInfo(map);
                            if (trainOrderR.getCode() == 200 && trainOrderR.getData() != null) {
                                TrainOrder trainOrder = trainOrderR.getData();
                                if (trainOrder.getStatus().equals(TrainOrderEnum.changeTicketSuccess.getValue())) {
                                    List<TrainOrderRefundrecord> change = remoteTrainService.queryTrainOrderRefundrecordList(trainOrder.getOrderid(), "change");
                                    if (change != null && change.size() > 0) {
                                        if (new BigDecimal(change.get(0).getDifferencePrice()).compareTo(new BigDecimal(0)) > 0) {
                                            //易宝信用卡退款
                                            if (change.get(0).getPayType().equals(BusinessTypeConstants.BankCredit.getValue())){
                                                Map<String, String> refundMap = new HashMap<>();
                                                refundMap.put("jsjOrderId", String.valueOf(change.get(0).getRecordid()));
                                                refundMap.put("bankTrxId", change.get(0).getBillNo());
                                                refundMap.put("moneyAmout", new BigDecimal(change.get(0).getDifferencePrice()).stripTrailingZeros().toPlainString());
                                                refundMap.put("payType", change.get(0).getSourceappid());
                                                yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                                            }
                                            //易宝借记卡退款
                                            else if (change.get(0).getPayType().equals(BusinessTypeConstants.BankDebit.getValue())){
                                                Map<String, String> refundMap = new HashMap<>();
                                                refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                                refundMap.put("bankTrxId", change.get(0).getBillNo());
                                                refundMap.put("moneyAmout", new BigDecimal(change.get(0).getDifferencePrice()).stripTrailingZeros().toPlainString());
                                                refundMap.put("payType", change.get(0).getSourceappid());
                                                yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                                            }else if (change.get(0).getPayType().equals(BusinessTypeConstants.Wechat.getValue()))
                                            {
                                                remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                                            }
                                            //-
                                            //银联二维码退款 TODO 后期完善
                                        /*else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                                            Map<String, String> refundMap = new HashMap<>();
                                            refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                            refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                                            refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                                            UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                                            if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                                                //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                                                refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                                                financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                                                return 0;
                                            }
                                        }*/
                                        }
                                    }
                                }
                                //易宝信用卡退款
                                if (trainOrder.getPayType().equals(BusinessTypeConstants.BankCredit.getValue())){
                                    Map<String, String> refundMap = new HashMap<>();
                                    refundMap.put("jsjOrderId", String.valueOf(trainOrder.getOrdernumber()));
                                    refundMap.put("bankTrxId", trainOrder.getBillNo());
                                    refundMap.put("moneyAmout", trainOrder.getPayamount().stripTrailingZeros().toPlainString());
                                    refundMap.put("payType", trainOrder.getSourceappid());
                                    yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                                }
                                //易宝借记卡退款
                                else if (trainOrder.getPayType().equals(BusinessTypeConstants.BankDebit.getValue())){
                                    Map<String, String> refundMap = new HashMap<>();
                                    refundMap.put("jsjOrderId", String.valueOf(trainOrder.getOrdernumber()));
                                    refundMap.put("bankTrxId", trainOrder.getBillNo());
                                    refundMap.put("moneyAmout", trainOrder.getPayamount().stripTrailingZeros().toPlainString());
                                    refundMap.put("payType", trainOrder.getSourceappid());
                                    yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                                }else if (trainOrder.getPayType().equals(BusinessTypeConstants.Wechat.getValue()))
                                {
                                    remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                                }
                                //-
                                //银联二维码退款 TODO 后期完善
                            /*else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                                Map<String, String> refundMap = new HashMap<>();
                                refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                                refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                                UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                                if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                                    //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                                    refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                                    financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                                    return 0;
                                }
                            }*/
                            }
                        }
                    } else if (financeOrderRefundment.getRefundmentType() == com.ktgj.common.core.constant.FinanceOrderRefundment.depositBusiness.getValue()) {
                        //TODO 退预留款后期完善
                    }else if (financeOrderRefundment.getRefundmentType() == com.ktgj.common.core.constant.FinanceOrderRefundment.mall.getValue())
                    {
                        Map<String, String> refundMap = new HashMap<>();
                        refundMap.put("jsjOrderId", String.valueOf(financeOrderRefundment.getOrderId()));
                        refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                        refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().toString());
                        refundMap.put("payType", "App");
                        if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.BankCredit.getValue()))
                        {
                            yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                        }
                        if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.BankDebit.getValue()))
                        {
                            yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                        }
                        if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.Wechat.getValue()))
                        {
                            wechatRefund(financeOrderRefundment);
                        }
                    }else if (financeOrderRefundment.getRefundmentType() == com.ktgj.common.core.constant.FinanceOrderRefundment.travel.getValue())
                    {
                        Map<String, String> refundMap = new HashMap<>();
                        refundMap.put("jsjOrderId", String.valueOf(financeOrderRefundment.getOrderId()));
                        refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                        refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().toString());
                        refundMap.put("payType", "App");
                        if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.BankCredit.getValue()))
                        {
                            yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                        }
                        if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.BankDebit.getValue()))
                        {
                            yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                        }
                        if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.Wechat.getValue()))
                        {
                            wechatRefund(financeOrderRefundment);
                        }
                    }
                }
            }catch (Exception e)
            {
                log.error(e.getMessage());
                System.out.println(e.getMessage());
                return 0;
            }
            return 1;
        } else {
            try
            {
                FinanceOrderRefundment refundment = new FinanceOrderRefundment();
                refundment.setRefundmentId(refundmentExamine.getRefundmentId());
                refundment.setStatus(refundmentExamine.getStatus());
                refundment.setEmployeeIdReturn(employee.getEmployeeId());
                refundment.setReturnTime(new Date());
                int orderRefundment = financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                if (orderRefundment == 0)
                    return orderRefundment;
                FinanceOrderRefundment financeOrderRefundment = financeOrderRefundmentMapper.selectFinanceOrderRefundmentById(refundmentExamine.getRefundmentId());
                if (financeOrderRefundment.getRefundmentType() == com.ktgj.common.core.constant.FinanceOrderRefundment.originalRoad.getValue()) {
                    if (financeOrderRefundment.getOrderTypeId() == com.ktgj.common.core.constant.FinanceOrderRefundment.customer.getValue()) {
                        BusinessOrder businessOrder = businessOrderService.selectBusinessOrderById(Long.valueOf(financeOrderRefundment.getOrderId()));
                        //易宝信用卡退款
                        if (businessOrder.getPayType().equals(BusinessTypeConstants.BankCredit.getValue())){
                            Map<String, String> refundMap = new HashMap<>();
                            refundMap.put("jsjOrderId", String.valueOf(businessOrder.getOrdernum()));
                            refundMap.put("bankTrxId", businessOrder.getPartyPayNum());
                            refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                            if (businessOrder.getSourceway() == 2) {
                                refundMap.put("payType", "Crm");
                            } else if (businessOrder.getSourceway() == 6) {
                                refundMap.put("payType", "App");
                            }
                            yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                        }
                        //易宝借记卡退款
                        else if (businessOrder.getPayType().equals(BusinessTypeConstants.BankDebit.getValue())){
                            Map<String, String> refundMap = new HashMap<>();
                            refundMap.put("jsjOrderId", String.valueOf(businessOrder.getOrdernum()));
                            refundMap.put("bankTrxId", businessOrder.getPartyPayNum());
                            refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                            if (businessOrder.getSourceway() == 2) {
                                refundMap.put("payType", "Crm");
                            } else if (businessOrder.getSourceway() == 6) {
                                refundMap.put("payType", "App");
                            }
                            yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                        }else if (businessOrder.getPayType().equals(BusinessTypeConstants.Wechat.getValue()))
                        {
                            remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                        }
                        //-
                        //银联二维码退款 TODO 后期完善
                    /*else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                        Map<String, String> refundMap = new HashMap<>();
                        refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                        refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                        refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                        UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                        if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                            //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                            refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                            financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                            return 0;
                        }
                    }*/
                    } else if (financeOrderRefundment.getOrderTypeId() == com.ktgj.common.core.constant.FinanceOrderRefundment.flight.getValue()) {
                        Map<String, Long> map = new HashMap<>();
                        map.put("orderId", Long.valueOf(financeOrderRefundment.getOrderId()));
                        R<FlightOrderInfo> orderInfo = remoteFlightService.getInfo(map);
                        if (orderInfo.getCode() == 200 && orderInfo.getData() != null) {
                            FlightOrderInfoTickets orderInfoTickets = new FlightOrderInfoTickets();
                            orderInfoTickets.setOrderId(Long.valueOf(financeOrderRefundment.getOrderId()));
                            List<FlightOrderInfoTickets> infoTickets = remoteFlightService.orderInfoTicketsList(orderInfoTickets);
                            for (FlightOrderInfoTickets infoTicket : infoTickets) {
                                if (infoTicket.getChangeDateOrderId() != null) {
                                    FlightOrderChangeTickets orderChangeTickets = new FlightOrderChangeTickets();
                                    orderChangeTickets.setOldTicketNo(infoTicket.getTicketNo());
                                    List<FlightOrderChangeTickets> ticketsList = remoteFlightService.orderChangeTicketsList(orderChangeTickets);
                                    for (FlightOrderChangeTickets flightOrderChangeTickets : ticketsList) {
                                        String[] split = flightOrderChangeTickets.getChangeOrderId().split("-");
                                        if (split[1].equals("G")) {
                                            if (flightOrderChangeTickets.getChangeFee().compareTo(new BigDecimal(0)) == 0) {
                                                break;
                                            } else {
                                                //易宝信用卡退款
                                                if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.BankCredit.getValue())){
                                                    Map<String, String> refundMap = new HashMap<>();
                                                    refundMap.put("jsjOrderId", String.valueOf(flightOrderChangeTickets.getChangeTicketId()));
                                                    refundMap.put("bankTrxId", flightOrderChangeTickets.getBillNo());
                                                    refundMap.put("moneyAmout", flightOrderChangeTickets.getChangeFee().stripTrailingZeros().toPlainString());
                                                    refundMap.put("payType", flightOrderChangeTickets.getSourceTypeId());
                                                    yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                                                }
                                                //易宝借记卡退款
                                                else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.BankDebit.getValue())){
                                                    Map<String, String> refundMap = new HashMap<>();
                                                    refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                                    refundMap.put("bankTrxId", flightOrderChangeTickets.getBillNo());
                                                    refundMap.put("moneyAmout", flightOrderChangeTickets.getChangeFee().stripTrailingZeros().toPlainString());
                                                    refundMap.put("payType", flightOrderChangeTickets.getSourceTypeId());
                                                    yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                                                }else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.Wechat.getValue()))
                                                {
                                                    remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                                                }
                                                //-
                                                //银联二维码退款 TODO 后期完善
                                            /*else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                                                Map<String, String> refundMap = new HashMap<>();
                                                refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                                refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                                                refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                                                UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                                                if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                                                    //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                                                    refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                                                    financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                                                    return 0;
                                                }
                                            }*/
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                            FlightOrderInfo flightOrderInfo = orderInfo.getData();
                            //易宝信用卡退款
                            if (flightOrderInfo.getPayType().equals(BusinessTypeConstants.BankCredit.getValue())){
                                Map<String, String> refundMap = new HashMap<>();
                                refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                                refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                refundMap.put("payType", flightOrderInfo.getSourceTypeId());
                                yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                            }
                            //易宝借记卡退款
                            else if (flightOrderInfo.getPayType().equals(BusinessTypeConstants.BankDebit.getValue())){
                                Map<String, String> refundMap = new HashMap<>();
                                refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                                refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                refundMap.put("payType", flightOrderInfo.getSourceTypeId());
                                yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                            }else if (flightOrderInfo.getPayType().equals(BusinessTypeConstants.Wechat.getValue()))
                            {
                                remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                            }
                            //-
                            //银联二维码退款 TODO 后期完善
                        /*else if (flightOrderInfo.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                            Map<String, String> refundMap = new HashMap<>();
                            refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                            refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                            refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                            UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                            if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                                //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                                refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                                financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                                return 0;
                            }
                        }*/
                        }
                    } else if (financeOrderRefundment.getOrderTypeId() == com.ktgj.common.core.constant.FinanceOrderRefundment.hotel.getValue()) {
                        R<HotelOrderPaydetail> orderPaydetailR = remoteHotelService.selectHotelOrderPaydetailByorderId(Long.valueOf(financeOrderRefundment.getOrderId()));
                        R<HotelOrder> info = remoteHotelService.getInfo(Long.valueOf(financeOrderRefundment.getOrderId()));
                        if (orderPaydetailR.getCode() == 200 && info.getCode() == 200 && orderPaydetailR.getData() != null && info.getData() != null) {
                            HotelOrderPaydetail data = orderPaydetailR.getData();
                            HotelOrder infoData = info.getData();
                            //易宝信用卡退款
                            if (data.getPaytype().equals(BusinessTypeConstants.BankCredit.getValue())){
                                Map<String, String> refundMap = new HashMap<>();
                                refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                                refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                refundMap.put("payType", infoData.getSourceWay());
                                yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                            }
                            //易宝借记卡退款
                            else if (data.getPaytype().equals(BusinessTypeConstants.BankDebit.getValue())){
                                Map<String, String> refundMap = new HashMap<>();
                                refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                                refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                refundMap.put("payType", infoData.getSourceWay());
                                yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                            }else if (data.getPaytype().equals(BusinessTypeConstants.Wechat.getValue()))
                            {
                                remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                            }
                            //-
                            //银联二维码退款 TODO 后期完善
                        /*else if (flightOrderInfo.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                            Map<String, String> refundMap = new HashMap<>();
                            refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                            refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                            refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                            UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                            if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                                //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                                refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                                financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                                return 0;
                            }
                        }*/
                        }
                    } else if (financeOrderRefundment.getOrderTypeId() == com.ktgj.common.core.constant.FinanceOrderRefundment.service.getValue()) {

                    } else if (financeOrderRefundment.getOrderTypeId() == com.ktgj.common.core.constant.FinanceOrderRefundment.train.getValue()) {
                        Map<String, Long> map = new HashMap<>();
                        map.put("orderid", Long.valueOf(financeOrderRefundment.getOrderId()));
                        R<TrainOrder> trainOrderR = remoteTrainService.getInfo(map);
                        if (trainOrderR.getCode() == 200 && trainOrderR.getData() != null) {
                            TrainOrder trainOrder = trainOrderR.getData();
                            if (trainOrder.getStatus().equals(TrainOrderEnum.changeTicketSuccess.getValue())) {
                                List<TrainOrderRefundrecord> change = remoteTrainService.queryTrainOrderRefundrecordList(trainOrder.getOrderid(), "change");
                                if (change != null && change.size() > 0) {
                                    if (new BigDecimal(change.get(0).getDifferencePrice()).compareTo(new BigDecimal(0)) > 0) {
                                        //易宝信用卡退款
                                        if (change.get(0).getPayType().equals(BusinessTypeConstants.BankCredit.getValue())){
                                            Map<String, String> refundMap = new HashMap<>();
                                            refundMap.put("jsjOrderId", String.valueOf(change.get(0).getRecordid()));
                                            refundMap.put("bankTrxId", change.get(0).getBillNo());
                                            refundMap.put("moneyAmout", new BigDecimal(change.get(0).getDifferencePrice()).stripTrailingZeros().toPlainString());
                                            refundMap.put("payType", change.get(0).getSourceappid());
                                            yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                                        }
                                        //易宝借记卡退款
                                        else if (change.get(0).getPayType().equals(BusinessTypeConstants.BankDebit.getValue())){
                                            Map<String, String> refundMap = new HashMap<>();
                                            refundMap.put("jsjOrderId", financeOrderRefundment.getOrderId());
                                            refundMap.put("bankTrxId", change.get(0).getBillNo());
                                            refundMap.put("moneyAmout", new BigDecimal(change.get(0).getDifferencePrice()).stripTrailingZeros().toPlainString());
                                            refundMap.put("payType", change.get(0).getSourceappid());
                                            yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                                        }else if (change.get(0).getPayType().equals(BusinessTypeConstants.Wechat.getValue()))
                                        {
                                            remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                                        }
                                        //-
                                        //银联二维码退款 TODO 后期完善
                                        /*else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                                            Map<String, String> refundMap = new HashMap<>();
                                            refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                            refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                                            refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                                            UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                                            if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                                                //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                                                refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                                                financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                                                return 0;
                                            }
                                        }*/
                                    }
                                }
                            }
                            //易宝信用卡退款
                            if (trainOrder.getPayType().equals(BusinessTypeConstants.BankCredit.getValue())){
                                Map<String, String> refundMap = new HashMap<>();
                                refundMap.put("jsjOrderId", String.valueOf(trainOrder.getOrdernumber()));
                                refundMap.put("bankTrxId", trainOrder.getBillNo());
                                refundMap.put("moneyAmout", trainOrder.getPayamount().stripTrailingZeros().toPlainString());
                                refundMap.put("payType", trainOrder.getSourceappid());
                                yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                            }
                            //易宝借记卡退款
                            else if (trainOrder.getPayType().equals(BusinessTypeConstants.BankDebit.getValue())){
                                Map<String, String> refundMap = new HashMap<>();
                                refundMap.put("jsjOrderId", String.valueOf(trainOrder.getOrdernumber()));
                                refundMap.put("bankTrxId", trainOrder.getBillNo());
                                refundMap.put("moneyAmout", trainOrder.getPayamount().stripTrailingZeros().toPlainString());
                                refundMap.put("payType", trainOrder.getSourceappid());
                                yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                            }else if (trainOrder.getPayType().equals(BusinessTypeConstants.Wechat.getValue()))
                            {
                                remotePayService.refundWechat(refundment.getOrderId(),refundment.getSerialnumber(),"",refundment.getRefundmentAmount(),refundment.getRefundmentAmount());
                            }
                            //-
                            //银联二维码退款 TODO 后期完善
                            /*else if (flightOrderChangeTickets.getPayType().equals(BusinessTypeConstants.UnionPayQRCode.getValue())){
                                Map<String, String> refundMap = new HashMap<>();
                                refundMap.put("refundAmount", financeOrderRefundment.getRefundmentAmount().stripTrailingZeros().toPlainString());
                                refundMap.put("billNo", financeOrderRefundment.getSerialnumber());
                                refundMap.put("notifyUrl", "http://106.38.39.137:8080/customer/callback/flightRefund");
                                UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(refundMap);
                                if (!unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                                    //throw new Exception("退款失败" + unionPayQRCodeResponseApi.getErrMsg());
                                    refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
                                    financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
                                    return 0;
                                }
                            }*/
                        }
                    }
                } else if (financeOrderRefundment.getRefundmentType() == com.ktgj.common.core.constant.FinanceOrderRefundment.depositBusiness.getValue()) {
                    //TODO 退预留款后期完善
                }else if (financeOrderRefundment.getRefundmentType() == com.ktgj.common.core.constant.FinanceOrderRefundment.mall.getValue())
                {
                    Map<String, String> refundMap = new HashMap<>();
                    refundMap.put("jsjOrderId", String.valueOf(financeOrderRefundment.getOrderId()));
                    refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                    refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().toString());
                    refundMap.put("payType", "App");
                    if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.BankCredit.getValue()))
                    {
                        yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                    }
                    if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.BankDebit.getValue()))
                    {
                        yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                    }
                    if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.Wechat.getValue()))
                    {
                        wechatRefund(financeOrderRefundment);
                    }
                }else if (financeOrderRefundment.getRefundmentType() == com.ktgj.common.core.constant.FinanceOrderRefundment.travel.getValue())
                {
                    Map<String, String> refundMap = new HashMap<>();
                    refundMap.put("jsjOrderId", String.valueOf(financeOrderRefundment.getOrderId()));
                    refundMap.put("bankTrxId", financeOrderRefundment.getSerialnumber());
                    refundMap.put("moneyAmout", financeOrderRefundment.getRefundmentAmount().toString());
                    refundMap.put("payType", "App");
                    if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.BankCredit.getValue()))
                    {
                        yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankCredit);
                    }
                    if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.BankDebit.getValue()))
                    {
                        yeeBaoRefund(refundMap,refundment,BusinessTypeConstants.BankDebit);
                    }
                    if (financeOrderRefundment.getPaymentTypeId().equals(BusinessTypeConstants.Wechat.getValue()))
                    {
                        wechatRefund(financeOrderRefundment);
                    }
                }
            }catch (Exception e)
            {
                log.error(e.getMessage());
                System.out.println(e.getMessage());
                return 0;
            }
            if (refundmentExamine.isSendSMS()) {
                Sms sms = new Sms();
                BASE64Decoder decoder = new BASE64Decoder();
                try {
                    byte[] bytes = decoder.decodeBuffer(refundmentExamine.getCustomerPhone());
                    String phone = new String(bytes, "UTF-8");
                    sms.setMobile(phone);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                sms.setSmsContent(refundmentExamine.getSendContent());
                remoteSmsService.sendSmsMessage(sms);
            }
            return 1;
        }
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public void yeeBaoRefund(Map<String,String> refundMap, FinanceOrderRefundment refundment, BusinessTypeConstants payType)
    {
        YeeBaoResultApi yeeBaoResultApi = new YeeBaoResultApi();
        if (payType.getValue().equals(BusinessTypeConstants.BankCredit.getValue()))
        {
            yeeBaoResultApi = remotePayService.bankCreditRefund(refundMap);
        }
        if (payType.getValue().equals(BusinessTypeConstants.BankDebit.getValue()))
        {
            yeeBaoResultApi = remotePayService.bankDebitRefund(refundMap);
        }
        if (!yeeBaoResultApi.getCode().equals("1"))
        {
            refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
            refundment.setReturnTime(new Date());
            financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
        } else if (yeeBaoResultApi.getCode().equals("1"))
        {
            refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.complete.toString()));
            refundment.setReturnTime(new Date());
            financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
        }
    }

    @Transactional(rollbackFor = Exception.class , propagation = Propagation.REQUIRED)
    public void wechatRefund(FinanceOrderRefundment refundment)
    {
        AjaxResult ajaxResult = remotePayService.refundWechat(refundment.getOrderId(), refundment.getSerialnumber(), "", refundment.getRefundmentAmount(), refundment.getRefundmentAmount());
        if (ajaxResult.get("code").equals(200))
        {
            refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.complete.toString()));
            refundment.setReturnTime(new Date());
            financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
        } else
        {
            refundment.setStatus(String.valueOf(com.ktgj.common.core.constant.FinanceOrderRefundment.refundFailed.toString()));
            refundment.setReturnTime(new Date());
            financeOrderRefundmentMapper.updateFinanceOrderRefundment(refundment);
        }
    }

}
